package com.itheima.health.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

public interface OrderSettingMapper extends BaseMapper<OrderSetting> {
    @Select("select orderdate , number ,reservations  from  t_ordersetting  where  ORDERDATE BETWEEN #{beginDate} and #{endDate}")
    List<Map> findOrderSettingsData(String beginDate, String endDate);

    @Update("update t_ordersetting set NUMBER = #{number} where ORDERDATE = #{orderdate}")
    void updataNumByDay(@Param("orderdate") String Day,
                        @Param("number") int num);

    //查询数据库是否存在该数据
    @Select("select ID from t_ordersetting where NUNMER>RESERVATIONS,ORDERDATE = #{orderdate}")
    Object findByDay(@Param("orderdate") String Day);


    //查询日期是否可预约
    @Select("select count(1) from t_ordersetting where ORDERDATE = #{orderDate} AND  NUMBER > RESERVATIONS ")
    int isOrderSetting(@Param("orderDate") String orderDate);

    //修改日期对应的预约人数
   @Update("update t_ordersetting set RESERVATIONS = RESERVATIONS+1 where ORDERDATE = #{orderDate}")
    void upDateReservationsByOrderFate(@Param("orderDate") String Date);


}
